<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
	<title></title>
	<style type="text/css">
	body{
		position:relative;
	}
		.box{
			width:100px;
			height:100px;
			background-color: yellow;
			position:absolute;
		}
	</style>
</head>
<body>
<div class="box"></div>
</body>
<script type="text/javascript">
    var box = document.getElementsByClassName('box')[0];
    box.onmousedown = function(event){
    	    var x1=event.clientX-box.offsetLeft;
    	    var y1=event.clientY-box.offsetTop;
	document.onmousemove = function(event){
			box.style.left=(event.clientX-x1)+'px';
			box.style.top=(event.clientY-y1)+'px';
}
}
document.onmouseup=function(){
document.onmousemove = "";
};
</script>
</html>